home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / Mesa / src-glut / glutGetSetColor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-02  |  1.9 KB  |  86 lines

  1. /*
  2.  * Amiga GLUT graphics library toolkit
  3.  * Version:  1.1
  4.  * Copyright (C) 1998 Jarno van der Linden
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Library General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Library General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Library General Public
  17.  * License along with this library; if not, write to the Free
  18.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  */
  20.  
  21.  
  22. /*
  23.  * glutGetSetColor.c
  24.  *
  25.  * Version 1.0  28 Jun 1998
  26.  * by Jarno van der Linden
  27.  * jarno@kcbbs.gen.nz
  28.  *
  29.  */
  30.  
  31.  
  32. #include <proto/graphics.h>
  33. #include <proto/intuition.h>
  34.  
  35. #include "glutstuff.h"
  36.  
  37.  
  38. GLfloat glutGetColor(int ndx, int component )
  39. {
  40.     ULONG table[3];
  41.  
  42.     if((ndx < 0) || (ndx > 255))
  43.         return(-1.0);
  44.  
  45.     GetRGB32(ViewPortAddress(glutstuff.curwin->window)->ColorMap, ndx - glutstuff.colourbase, 1, table);
  46.  
  47.     switch(component)
  48.     {
  49.         case GLUT_RED:
  50.             return((GLfloat)(((GLfloat)table[0])/0xffffffff));
  51.         case GLUT_GREEN:
  52.             return((GLfloat)(((GLfloat)table[1])/0xffffffff));
  53.         case GLUT_BLUE:
  54.             return((GLfloat)(((GLfloat)table[2])/0xffffffff));
  55.     }
  56.  
  57.     return(-1.0);
  58. }
  59.  
  60.  
  61. void glutSetColor(int cell, GLfloat red, GLfloat green, GLfloat blue)
  62. {
  63.     ULONG r,g,b;
  64.  
  65.     if(red < 0.0)
  66.         red = 0.0;
  67.     else if(red > 1.0)
  68.         red = 1.0;
  69.  
  70.     if(green < 0.0)
  71.         green = 0.0;
  72.     else if(green > 1.0)
  73.         green = 1.0;
  74.  
  75.     if(blue < 0.0)
  76.         blue = 0.0;
  77.     else if(blue > 1.0)
  78.         blue = 1.0;
  79.  
  80.     r = (ULONG)(red * 0xffffffff);
  81.     g = (ULONG)(green * 0xffffffff);
  82.     b = (ULONG)(blue * 0xffffffff);
  83.  
  84.     SetRGB32(ViewPortAddress(glutstuff.curwin->window), glutstuff.colourbase + cell, r, g, b);
  85. }
  86.